package com.lcc.spring;

import java.lang.reflect.Field;

/**
 * <一句话功能描述> 获取value值
 * <功能详细描述>
 *
 * @author Mr Lcc
 * @version [版本号, 2024/11/23]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Component
public class LccValueBeanPostProcessor implements BeanPostProcessor{
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) {

        for (Field field : bean.getClass().getDeclaredFields()) {
            if (field.isAnnotationPresent(LccValue.class)) {
                field.setAccessible(true);
                try {
                    field.set(bean, field.getAnnotation(LccValue.class).value());
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }

        // bean
        return bean;
    }

}
